﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using studentSubsidy.Entity.User;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class UserDao
    {
        private SqlCommandExecutor _sqlCommandExecutor = new SqlCommandExecutor();
        private MyDbContext DBContext = new MyDbContext();
        
        public void insertUser(RegisterQuery registerQuery)
        {
            DBContext.Add(new User(GenerateID.GenerateId(), registerQuery.Username, registerQuery.Name,
                AESUtils.Encrypt(registerQuery.Password), registerQuery.Major, registerQuery.Enrollment.ToString("u"),
                registerQuery.Address, registerQuery.Phone, registerQuery.Remark, registerQuery.Role));
        }

        public List<User> ifUserByPassword(UserLoginQuery userLoginQuery)
        {
            List<User> user = DBContext.User.Where(p =>
                p.username == userLoginQuery.Username && p.password == userLoginQuery.Password).ToList();
            return user;
        }

        public List<User> getAllUser()
        {
            List<User> user = DBContext.User.ToList();
            return user;
        }
        
    }
}